auth.js ➔ open_popup   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
dl 0
loc 12
rs 9.95
c 0
b 0
f 0
1
/**
2
 * Method checks login window status
3
 * 
4
 * @param Popup
5
 *            window object
6
 * @param Handler
7
 *            login handler
8
 */
9
function check_login_status(Popup, Handler) {
10
	return (function() {
11
		if (Popup.closed) {
12
			Handler()
13
		} else {
14
			setTimeout(check_login_status(Popup, Handler), 100)
15
		}
16
	})
17
}
18
19
/**
20
 * Method calculates screen's center
21
 */ 
22
function screen_center_pos(PopUpWidth, PopUpHeight)
23
{
24
	var Width = $(window).width()
25
26
	var Height = $(window).height()
27
28
	return({
29
		x : (Width/2 - PopUpWidth/2) , 
30
		y : (Height/2 - PopUpHeight/2)
31
	})
32
}
33
34
/**
35
 * Open login pop up
36
 * 
37
 * @param URL
38
 *            Login url
39
 * @param Title
40
 *            Popup title
41
 * @param Handler
42
 *            OnLogin handler
43
 */
44
function open_popup(URL, Title, Handler) {
45
	return (function() {
46
		var PopupWidth = Math.min($(window).width(), 800)
47
		var PopupHeight = Math.min($(window).height(), 600)
48
		var Pos = screen_center_pos(PopupWidth, PopupHeight)
49
		var Params = "width=" + PopupWidth + ",height=" + PopupHeight + ",toolbar=0,scrollbars=0,status=0,resizable=0,location=0,menuBar=0,left=" + Pos.x + ",top=" + Pos.y
50
51
		var Popup = window.open(URL, Title, Params)
52
		setTimeout(check_login_status(Popup, Handler), 2000)
53
		Popup.focus()
54
	})
55
}
56
57
/**
58
 * Setup login pop up
59
 * 
60
 * @param $Button
61
 *            Trigger button
62
 * @param URL
63
 *            Login url
64
 * @param Title
65
 *            Popup title
66
 * @param Handler
67
 *            OnLogin handler
68
 */
69
function setup_social_media_login_popup($Button, URL, Title, Handler) {
70
	$Button.click(open_popup(URL, Title, Handler));
71
}